﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCRUM.Core.BusinessObjects;
using System.Data.Common;

namespace SCRUM.Core.DataProviders
{
    /// <summary>
    /// Privider for comunication with the database for attachments
    /// </summary>
    public partial class DBDataProvider : DataProvider
    {
        /// <summary>
        /// Gets all attachments for the specified userStory.
        /// </summary>
        /// <param name="userStoryID">The specific ID of UserStory.</param>\
        /// <returns>List of attachments for Userstory</returns>
        public override List<Attachment> GetAttachmetnsForUserStory(int userStoryID)
        {
            List<Attachment> output = new List<Attachment>();

            DbParameter dbuserStoryID = CreateParameter("userStoryID", userStoryID);
            try
            {
                connection.Open();
                DbDataReader data = GetGrid("attachment/GetAttachmetnsForUserStory", dbuserStoryID);

                while (data.Read())
                {
                    Attachment att = new Attachment(
                        (int)data["ID"],
                        (string)data["FILE_NAME"],
                        (string)data["PATH"]
                        );

                    output.Add(att);
                }
            }
            finally
            {
                connection.Close();
            }
            return output;
        }

    }
}
